home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivmlctrl.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  13.2 KB  |  637 lines

  1. unit IvMlCtrl;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8. {$IFDEF WIN32}
  9.   Windows,
  10. {$ELSE}
  11.   WinTypes, WinProcs,
  12. {$ENDIF}
  13.   Classes, Graphics, Controls, Menus, Forms, Stdctrls, ExtCtrls;
  14.  
  15. type
  16.   { Label }
  17.  
  18. {$IFNDEF IVBIDI}
  19.   TIvCustomLabel = class(TCustomLabel)
  20.   private
  21.   {$IFDEF WIN32}
  22.     {$IFNDEF VER110}
  23.     procedure DoDrawText(var rect: TRect; flags: Integer);
  24.     {$ENDIF}
  25.   {$ENDIF}
  26.  
  27.   protected
  28.     FLocale: Integer;
  29.  
  30.     procedure SetLocale(value: Integer);
  31.  
  32.   {$IFDEF VER110}
  33.     procedure DoDrawText(var rect: TRect; flags: Word); override;
  34.   {$ENDIF}
  35.   {$IFDEF WIN32}
  36.     procedure Paint; override;
  37.   {$ENDIF}
  38.  
  39.   public
  40.     constructor Create(owner: TComponent); override;
  41.  
  42.     property Locale: Integer read FLocale write SetLocale;
  43.   end;
  44. {$ENDIF}
  45.  
  46. {$IFDEF IVBIDI}
  47.   TIvLabel = class(TLabel)
  48.   end;
  49. {$ELSE}
  50.   TIvLabel = class(TIvCustomLabel)
  51.   published
  52.     property Align;
  53.     property Alignment;
  54.     property AutoSize;
  55.     property Caption;
  56.     property Color;
  57.     property DragCursor;
  58.     property DragMode;
  59.     property Enabled;
  60.     property FocusControl;
  61.     property Font;
  62.     property Locale stored False;
  63.     property ParentColor;
  64.     property ParentFont;
  65.     property ParentShowHint;
  66.     property PopupMenu;
  67.     property ShowAccelChar;
  68.     property ShowHint;
  69.     property Transparent;
  70.   {$IFDEF IVWIDE}
  71.     property Layout;
  72.   {$ENDIF}
  73.     property Visible;
  74.     property WordWrap;
  75.     property OnClick;
  76.     property OnDblClick;
  77.     property OnDragDrop;
  78.     property OnDragOver;
  79.     property OnEndDrag;
  80.     property OnMouseDown;
  81.     property OnMouseMove;
  82.     property OnMouseUp;
  83.   {$IFDEF WIN32}
  84.     property OnStartDrag;
  85.   {$ENDIF}
  86.   end;
  87. {$ENDIF}
  88.  
  89.   { Group box }
  90.  
  91. {$IFNDEF IVBIDI}
  92.   TIvCustomGroupBox = class(TCustomGroupBox)
  93.   protected
  94.     FLocale: Integer;
  95.  
  96.     procedure SetLocale(value: Integer);
  97.  
  98.   {$IFDEF WIN32}
  99.     procedure Paint; override;
  100.   {$ENDIF}
  101.  
  102.   public
  103.     constructor Create(owner: TComponent); override;
  104.  
  105.     property Locale: Integer read FLocale write SetLocale;
  106.   end;
  107. {$ENDIF}
  108.  
  109. {$IFDEF IVBIDI}
  110.   TIvGroupBox = class(TGroupBox)
  111.   end;
  112. {$ELSE}
  113.   TIvGroupBox = class(TIvCustomGroupBox)
  114.   published
  115.     property Align;
  116.     property Caption;
  117.     property Color;
  118.     property Ctl3D;
  119.     property DragCursor;
  120.     property DragMode;
  121.     property Enabled;
  122.     property Font;
  123.     property Locale stored False;
  124.     property ParentColor;
  125.     property ParentCtl3D;
  126.     property ParentFont;
  127.     property ParentShowHint;
  128.     property PopupMenu;
  129.     property ShowHint;
  130.     property TabOrder;
  131.     property TabStop;
  132.     property Visible;
  133.     property OnClick;
  134.     property OnDblClick;
  135.     property OnDragDrop;
  136.     property OnDragOver;
  137.     property OnEndDrag;
  138.     property OnEnter;
  139.     property OnExit;
  140.     property OnMouseDown;
  141.     property OnMouseMove;
  142.     property OnMouseUp;
  143.   {$IFDEF WIN32}
  144.     property OnStartDrag;
  145.   {$ENDIF}
  146.   end;
  147. {$ENDIF}
  148.  
  149.   { Radio box }
  150.  
  151. {$IFNDEF IVBIDI}
  152.   TIvCustomRadioGroup = class(TCustomRadioGroup)
  153.   protected
  154.     FLocale: Integer;
  155.  
  156.     procedure SetLocale(value: Integer);
  157.  
  158.   {$IFDEF WIN32}
  159.     procedure Paint; override;
  160.   {$ENDIF}
  161.  
  162.   public
  163.     constructor Create(owner: TComponent); override;
  164.  
  165.     property Locale: Integer read FLocale write SetLocale;
  166.   end;
  167. {$ENDIF}
  168.  
  169. {$IFDEF IVBIDI}
  170.   TIvRadioGroup = class(TRadioGroup)
  171.   end;
  172. {$ELSE}
  173.   TIvRadioGroup = class(TIvCustomRadioGroup)
  174.   published
  175.     property Align;
  176.     property Caption;
  177.     property Color;
  178.     property Columns;
  179.     property Ctl3D;
  180.     property DragCursor;
  181.     property DragMode;
  182.     property Enabled;
  183.     property Font;
  184.     property ItemIndex;
  185.     property Items;
  186.     property Locale stored False;
  187.     property ParentColor;
  188.     property ParentCtl3D;
  189.     property ParentFont;
  190.     property ParentShowHint;
  191.     property PopupMenu;
  192.     property ShowHint;
  193.     property TabOrder;
  194.     property TabStop;
  195.     property Visible;
  196.     property OnClick;
  197.     property OnDragDrop;
  198.     property OnDragOver;
  199.     property OnEndDrag;
  200.     property OnEnter;
  201.     property OnExit;
  202.   {$IFDEF WIN32}
  203.     property OnStartDrag;
  204.   {$ENDIF}
  205.   end;
  206. {$ENDIF}
  207.  
  208.   { List box }
  209.  
  210. {$IFNDEF IVBIDI}
  211.   TIvCustomListBox = class(TCustomListBox)
  212.   private
  213.     FLocale: Integer;
  214.  
  215.     procedure SetLocale(value: Integer);
  216.  
  217.   protected
  218.     procedure CreateParams(var Params: TCreateParams); override;
  219.  
  220.   public
  221.     constructor Create(owner: TComponent); override;
  222.  
  223.     property Locale: Integer read FLocale write SetLocale;
  224.   end;
  225. {$ENDIF}
  226.  
  227. {$IFDEF IVBIDI}
  228.   TIvListBox = class(TListBox)
  229.   end;
  230. {$ELSE}
  231.   TIvListBox = class(TIvCustomListBox)
  232.   published
  233.     property Align;
  234.     property BorderStyle;
  235.     property Color;
  236.     property Columns;
  237.     property Ctl3D;
  238.     property DragCursor;
  239.     property DragMode;
  240.     property Enabled;
  241.     property ExtendedSelect;
  242.     property Font;
  243.   {$IFDEF IVIME}
  244.     property ImeMode;
  245.     property ImeName;
  246.   {$ENDIF}
  247.     property IntegralHeight;
  248.     property ItemHeight;
  249.     property Items;
  250.     property Locale stored False;
  251.     property MultiSelect;
  252.     property ParentColor;
  253.     property ParentCtl3D;
  254.     property ParentFont;
  255.     property ParentShowHint;
  256.     property PopupMenu;
  257.     property ShowHint;
  258.     property Sorted;
  259.     property Style;
  260.     property TabOrder;
  261.     property TabStop;
  262.   {$IFDEF WIN32}
  263.     property TabWidth;
  264.   {$ENDIF}
  265.     property Visible;
  266.     property OnClick;
  267.     property OnDblClick;
  268.     property OnDragDrop;
  269.     property OnDragOver;
  270.     property OnDrawItem;
  271.     property OnEndDrag;
  272.     property OnEnter;
  273.     property OnExit;
  274.     property OnKeyDown;
  275.     property OnKeyPress;
  276.     property OnKeyUp;
  277.     property OnMeasureItem;
  278.     property OnMouseDown;
  279.     property OnMouseMove;
  280.     property OnMouseUp;
  281.   {$IFDEF WIN32}
  282.     property OnStartDrag;
  283.   {$ENDIF}
  284.   end;
  285. {$ENDIF}
  286.  
  287.   { Combo box }
  288.  
  289. {$IFNDEF IVBIDI}
  290.   TIvCustomComboBox = class(TCustomComboBox)
  291.   private
  292.     FLocale: Integer;
  293.  
  294.     procedure SetLocale(value: Integer);
  295.  
  296.   protected
  297.     procedure CreateParams(var Params: TCreateParams); override;
  298.  
  299.   public
  300.     constructor Create(owner: TComponent); override;
  301.  
  302.     property Locale: Integer read FLocale write SetLocale;
  303.   end;
  304. {$ENDIF}
  305.  
  306. {$IFDEF IVBIDI}
  307.   TIvComboBox = class(TComboBox)
  308.   end;
  309. {$ELSE}
  310.   TIvComboBox = class(TIvCustomComboBox)
  311.   published
  312.     property Style; {Must be published before Items}
  313.     property Color;
  314.     property Ctl3D;
  315.     property DragMode;
  316.     property DragCursor;
  317.     property DropDownCount;
  318.     property Enabled;
  319.     property Font;
  320.   {$IFDEF IVIME}
  321.     property ImeMode;
  322.     property ImeName;
  323.   {$ENDIF}
  324.     property ItemHeight;
  325.     property Items;
  326.     property Locale stored False;
  327.     property MaxLength;
  328.     property ParentColor;
  329.     property ParentCtl3D;
  330.     property ParentFont;
  331.     property ParentShowHint;
  332.     property PopupMenu;
  333.     property ShowHint;
  334.     property Sorted;
  335.     property TabOrder;
  336.     property TabStop;
  337.     property Text;
  338.     property Visible;
  339.     property OnChange;
  340.     property OnClick;
  341.     property OnDblClick;
  342.     property OnDragDrop;
  343.     property OnDragOver;
  344.     property OnDrawItem;
  345.     property OnDropDown;
  346.     property OnEndDrag;
  347.     property OnEnter;
  348.     property OnExit;
  349.     property OnKeyDown;
  350.     property OnKeyPress;
  351.     property OnKeyUp;
  352.     property OnMeasureItem;
  353.   {$IFDEF WIN32}
  354.     property OnStartDrag;
  355.   {$ENDIF}
  356.   end;
  357. {$ENDIF}
  358.  
  359. implementation
  360.  
  361. {$IFNDEF IVBIDI}
  362. uses
  363.   {$IFNDEF WIN32}
  364.   SysUtils,
  365.   {$ENDIF}
  366.   IvDictio, IvMulti;
  367.  
  368. { TIvCustomLabel }
  369.  
  370. constructor TIvCustomLabel.Create(owner: TComponent);
  371. begin
  372.   inherited Create(owner);
  373.   FLocale := 0;
  374. end;
  375.  
  376. procedure TIvCustomLabel.SetLocale(value: Integer);
  377. begin
  378.   if value <> FLocale then
  379.   begin
  380.     FLocale := value;
  381.     Invalidate;
  382.   end;
  383. end;
  384.  
  385. {$IFDEF WIN32}
  386.   {$IFDEF VER110}
  387. procedure TIvCustomLabel.DoDrawText(var rect: TRect; flags: Word);
  388.   {$ELSE}
  389. procedure TIvCustomLabel.DoDrawText(var rect: TRect; flags: Integer);
  390.   {$ENDIF}
  391. var
  392.   Text: String;
  393. begin
  394.   Text := GetLabelText;
  395.   if (Flags and DT_CALCRECT <> 0) and ((Text = '') or ShowAccelChar and
  396.     (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' ';
  397.   if not ShowAccelChar then
  398.     Flags := Flags or DT_NOPREFIX;
  399.   Canvas.Font := Font;
  400.  
  401.  
  402. {$IFDEF IVWIDE}
  403.   if not Enabled then
  404.   begin
  405.     OffsetRect(Rect, 1, 1);
  406.     Canvas.Font.Color := clBtnHighlight;
  407.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  408.     OffsetRect(Rect, -1, -1);
  409.     Canvas.Font.Color := clBtnShadow;
  410.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  411.   end
  412.   else
  413.     DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  414. {$ELSE}
  415.   if not Enabled then
  416.     Canvas.Font.Color := clGrayText;
  417.   DrawTextEx(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags, nil);
  418. {$ENDIF}
  419. end;
  420.  
  421. procedure TIvCustomLabel.Paint;
  422. const
  423.   Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  424.   BidiAlignments: array[TAlignment] of Word = (DT_RIGHT, DT_LEFT, DT_CENTER);
  425.   WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);
  426. var
  427.   Rect: TRect;
  428.   DrawStyle: Integer;
  429. begin
  430.   with Canvas do
  431.   begin
  432.     if not Transparent then
  433.     begin
  434.       Brush.Color := Self.Color;
  435.       Brush.Style := bsSolid;
  436.       FillRect(ClientRect);
  437.     end;
  438.     Brush.Style := bsClear;
  439.     Rect := ClientRect;
  440.     DrawStyle := DT_EXPANDTABS or WordWraps[WordWrap];
  441.       DrawStyle := DrawStyle or Alignments[Alignment];
  442. {$IFDEF IVWIDE}
  443.     { Calculate vertical layout }
  444.     if Layout <> tlTop then
  445.     begin
  446.       DoDrawText(Rect, DrawStyle or DT_CALCRECT);
  447.       if Layout = tlBottom then
  448.         OffsetRect(Rect, 0, Height - Rect.Bottom)
  449.       else
  450.         OffsetRect(Rect, 0, (Height - Rect.Bottom) div 2);
  451.     end;
  452. {$ENDIF}
  453.     DoDrawText(Rect, DrawStyle);
  454.   end;
  455. end;
  456. {$ENDIF}
  457.  
  458.  
  459. { TIvCustomGroupBox }
  460.  
  461. constructor TIvCustomGroupBox.Create(owner: TComponent);
  462. begin
  463.   inherited Create(owner);
  464.   FLocale := 0;
  465. end;
  466.  
  467. procedure TIvCustomGroupBox.SetLocale(value: Integer);
  468. begin
  469.   if value <> FLocale then
  470.   begin
  471.     FLocale := value;
  472.     Invalidate;
  473.   end;
  474. end;
  475.  
  476. {$IFDEF WIN32}
  477. procedure TIvCustomGroupBox.Paint;
  478. var
  479.   H, flags: Integer;
  480.   R: TRect;
  481. begin
  482.   with Canvas do
  483.   begin
  484.     Font := Self.Font;
  485.     H := TextHeight('0');
  486.     R := Rect(0, H div 2 - 1, Width, Height);
  487.     if Ctl3D then
  488.     begin
  489.       Inc(R.Left);
  490.       Inc(R.Top);
  491.       Brush.Color := clBtnHighlight;
  492.       FrameRect(R);
  493.       OffsetRect(R, -1, -1);
  494.       Brush.Color := clBtnShadow;
  495.     end else
  496.       Brush.Color := clWindowFrame;
  497.     FrameRect(R);
  498.     if Text <> '' then
  499.     begin
  500.         flags := 0;
  501.  
  502.       R := Rect(8, 0, Width - 16, H);
  503.       DrawTextEx(
  504.         Handle,
  505.         PChar(Text),
  506.         Length(Text),
  507.         R,
  508.         flags or DT_LEFT or DT_SINGLELINE or DT_CALCRECT,
  509.         nil);
  510.  
  511.       Brush.Color := Color;
  512.  
  513.       DrawTextEx(
  514.         Handle,
  515.         PChar(Text),
  516.         Length(Text),
  517.         R,
  518.         flags or DT_LEFT or DT_SINGLELINE,
  519.         nil);
  520.     end;
  521.   end;
  522. end;
  523. {$ENDIF}
  524.  
  525.  
  526. { TIvCustomRadioGroup }
  527.  
  528. constructor TIvCustomRadioGroup.Create(owner: TComponent);
  529. begin
  530.   inherited Create(owner);
  531.   FLocale := 0;
  532. end;
  533.  
  534. procedure TIvCustomRadioGroup.SetLocale(value: Integer);
  535. begin
  536.   if value <> FLocale then
  537.   begin
  538.     FLocale := value;
  539.     Invalidate;
  540.   end;
  541. end;
  542.  
  543. {$IFDEF WIN32}
  544. procedure TIvCustomRadioGroup.Paint;
  545. var
  546.   H, flags: Integer;
  547.   R: TRect;
  548. begin
  549.   with Canvas do
  550.   begin
  551.     Font := Self.Font;
  552.     H := TextHeight('0');
  553.     R := Rect(0, H div 2 - 1, Width, Height);
  554.     if Ctl3D then
  555.     begin
  556.       Inc(R.Left);
  557.       Inc(R.Top);
  558.       Brush.Color := clBtnHighlight;
  559.       FrameRect(R);
  560.       OffsetRect(R, -1, -1);
  561.       Brush.Color := clBtnShadow;
  562.     end else
  563.       Brush.Color := clWindowFrame;
  564.     FrameRect(R);
  565.     if Text <> '' then
  566.     begin
  567.         flags := 0;
  568.  
  569.       R := Rect(8, 0, Width - 16, H);
  570.       DrawTextEx(
  571.         Handle,
  572.         PChar(Text),
  573.         Length(Text),
  574.         R,
  575.         flags or DT_LEFT or DT_SINGLELINE or DT_CALCRECT,
  576.         nil);
  577.  
  578.       Brush.Color := Color;
  579.  
  580.       DrawTextEx(
  581.         Handle,
  582.         PChar(Text),
  583.         Length(Text),
  584.         R,
  585.         flags or DT_LEFT or DT_SINGLELINE,
  586.         nil);
  587.     end;
  588.   end;
  589. end;
  590. {$ENDIF}
  591.  
  592. { TIvCustomListBox }
  593.  
  594. constructor TIvCustomListBox.Create(owner: TComponent);
  595. begin
  596.   inherited Create(owner);
  597.   FLocale := 0;
  598. end;
  599.  
  600. procedure TIvCustomListBox.SetLocale(value: Integer);
  601. begin
  602.   if value <> FLocale then
  603.   begin
  604.     FLocale := value;
  605.   end;
  606. end;
  607.  
  608. procedure TIvCustomListBox.CreateParams(var Params: TCreateParams);
  609. begin
  610.   inherited CreateParams(params);
  611. end;
  612.  
  613.  
  614. { TIvCustomComboBox }
  615.  
  616. constructor TIvCustomComboBox.Create(owner: TComponent);
  617. begin
  618.   inherited Create(owner);
  619.   FLocale := 0;
  620. end;
  621.  
  622. procedure TIvCustomComboBox.SetLocale(value: Integer);
  623. begin
  624.   if value <> FLocale then
  625.   begin
  626.     FLocale := value;
  627.   end;
  628. end;
  629.  
  630. procedure TIvCustomComboBox.CreateParams(var Params: TCreateParams);
  631. begin
  632.   inherited CreateParams(params);
  633. end;
  634. {$ENDIF}
  635.  
  636. end.
  637.